home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 36 / pc_ipc.zip / TX_PROC.C < prev   
Text File  |  1989-11-17  |  5KB  |  139 lines

  1. /************************************************************************/
  2. /*                                    */
  3. /*   TX_PROC.C : A demonstration of IPC usage for a Sending process.    */
  4. /*                                    */
  5. /*   Copyrighted (c) 1989 Donnelly Software Engineering.        */
  6. /*                                    */
  7. /*  This program should be compiled using the Large data model        */
  8. /*  (compact, large, or huge). If your compiler does not support the    */
  9. /*  Large data model, you need to devise a method of creating far    */
  10. /*  pointers for both 'p_block_ptr' and 'data_ptr' for this (or any    */
  11. /*  other IPC-based) program to work correctly. Below are examples of    */
  12. /*  creating TX_PROC.EXE using Borland International's TurboC (ver 1.5).*/
  13. /*                                    */
  14. /*    Compile and Link in one command:                */
  15. /*  TCC -ml -IC:\TURBOC\INCLUDE -LC:\TURBOC\LIB TX_PROC.C IPCLIB.LIB    */
  16. /*    Compile TX_PROC.C using the large memory model. The include    */
  17. /*    directory is c:\turboc\include. The library directory is    */
  18. /*    c:\turboc\lib. Link using the library IPCLIB.LIB.        */
  19. /*                                    */
  20. /*    Compile only :                            */
  21. /*  TCC -ml -c -IC:\TURBOC\INCLUDE TX_PROC.C                */
  22. /*    Compile TX_PROC.C using the large memory model. Compile to    */
  23. /*    object only. The include directory is c:\turboc\include.    */
  24. /*                                    */
  25. /*    Link only :                            */
  26. /*  TLINK C:\TURBOC\LIB\C0L.OBJ TX_PROC.OBJ, TX_PROC.EXE, TX_PROC.MAP,    */
  27. /*   IPCLIB.LIB C:\TURBOC\LIB\CL.LIB                    */
  28. /*    Link the large-model startup module C0L.OBJ, TX_PROC.OBJ,    */
  29. /*    IPCLIB.LIB, and the large-model run-time library CL.LIB to    */
  30. /*    produce TX_PROC.EXE and TX_PROC.MAP.                */
  31. /*                                    */
  32. /*    Run :                                */
  33. /*  TX_PROC [some data]                            */
  34. /*    Run TX_PROC.EXE. If any data is specified on the command line,    */
  35. /*    it will be sent to IPC. Otherwise, default data is sent.    */
  36. /*                                    */
  37. /************************************************************************/
  38.  
  39. #include <stdio.h>        /* standard i/o routines */
  40. #include "pc-ipc.h"        /* contains PC-IPC defines and structure */
  41.  
  42. main(argc, argv)        /* start of main program */
  43.     int argc;
  44.     char *argv[];
  45. {
  46.                 /*  DATA DECLARATIONS */
  47.  
  48.     int i;                /* loop counter */
  49.     char my_data[128];            /* a 128-byte data buffer */
  50.     IPC_PARAM_BLOCK far *p_block_ptr;    /* an IPC_PARAM_BLOCK far pointer */
  51.     unsigned int proc_1_id = 0;        /* storage for process ids */
  52.     unsigned int proc_2_id;
  53.     int dv_running;            /* TRUE if RX_PROC started first */
  54.  
  55.  
  56. /* determine if IPC is installed at the default vector */
  57.     if ( ! pc_ipc_installed(IPC_VECTOR) )
  58.         {
  59.         printf("IPC not installed at vector %02X.\n", IPC_VECTOR);
  60.         exit();
  61.        }
  62.  
  63. /* allocate some memory for an IPC_PARAMETER_BLOCK */
  64.     p_block_ptr = (IPC_PARAM_BLOCK far *)(malloc(sizeof(IPC_PARAM_BLOCK)));
  65.  
  66. /* if there is a message for process 0, RX_PROC is already waiting */
  67.     init_param_block(p_block_ptr, proc_1_id, 0, IPC_CMND_INQUIRE, 0, 0L);
  68.     pc_ipc(IPC_VECTOR, p_block_ptr);
  69.  
  70.     if (( !(p_block_ptr->error)) && (p_block_ptr->status & IPC_STAT_AVDATA))
  71.         {
  72.         init_param_block(p_block_ptr, proc_1_id, 0, IPC_CMND_RDATA,    0,
  73.                         (void far *)(&proc_2_id));
  74.         pc_ipc(IPC_VECTOR, p_block_ptr);
  75.  
  76.         if (p_block_ptr->status && IPC_STAT_ERROR)
  77.         ipc_error(p_block_ptr->error);
  78.  
  79.         dv_running = IPC_TRUE;
  80.         }
  81.  
  82. /* No, get a second process id and send it to process 0 for RX_PROC to find */
  83.     else
  84.         {
  85.         init_param_block(p_block_ptr, 0, 0, IPC_CMND_REQID, 0, 0L);
  86.         pc_ipc(IPC_VECTOR, p_block_ptr);
  87.  
  88.         if (p_block_ptr->error)
  89.         ipc_error(p_block_ptr->error);
  90.  
  91.         proc_2_id = p_block_ptr->my_id;
  92.  
  93.         init_param_block(p_block_ptr, proc_2_id, proc_1_id, IPC_CMND_SDATA,
  94.                 sizeof(unsigned int), (void far *)(&proc_2_id));
  95.         pc_ipc(IPC_VECTOR, p_block_ptr);
  96.  
  97.         dv_running = IPC_FALSE;
  98.         }
  99.  
  100. /* If any parameters are on the command line, send them as data */
  101.     if (argc > 1)
  102.         {
  103.         for (i = 1; i < argc; i++)
  104.         {
  105.         if (i == 1)
  106.             strcpy(my_data, argv[i]);
  107.         else
  108.             strcat(my_data, argv[i]);
  109.         if (i < argc - 1)
  110.             strcat(my_data, " ");
  111.         }
  112.         }
  113.     else
  114.         strcpy(my_data, "Howdy Doody and Buffalo Bob");
  115.  
  116. /* Send the data */
  117.     init_param_block(p_block_ptr, proc_1_id, proc_2_id, IPC_CMND_SDATA,
  118.             strlen(my_data) + 1, (void far *)(my_data));
  119.     pc_ipc(IPC_VECTOR, p_block_ptr);
  120.  
  121.     if (p_block_ptr->status & IPC_STAT_ERROR)
  122.         ipc_error(p_block_ptr->error);
  123.  
  124.     else
  125.         printf("Successfully sent \"%s\" from process-%d to process-%d.\n",
  126.             my_data, proc_1_id, proc_2_id);
  127.  
  128. /* relinquish the process id if one was allocated */
  129.     if ( !dv_running )
  130.         {
  131.         init_param_block(p_block_ptr, proc_2_id, 0, IPC_CMND_DELID, 0, 0L);
  132.         pc_ipc(IPC_VECTOR, p_block_ptr);
  133.         }
  134.  
  135. /* free the allocated far-memory for the IPC_PARAM_BLOCK */
  136.     free(p_block_ptr);
  137.  
  138. }    /* end of procedure main */
  139.